package com.example.hospitalmanagement.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.bean.DepartmentListData
import com.example.hospitalmanagement.bean.SecondaryLinkageItem

class DoctorPopupWindowAdapter(context: Context) :
    RecyclerView.Adapter<DoctorPopupWindowAdapter.PopupWindowHolder>() {
    private val context = context
    lateinit var dataList: MutableList<DepartmentListData>
    private lateinit var listener: (position: Int) -> Unit
    fun setListener(listener: (position: Int) -> Unit) {
        this.listener = listener
    }

    class PopupWindowHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val itemText: TextView = itemView.findViewById(R.id.popup_window_item_name)
        val itemIcon: ImageView = itemView.findViewById(R.id.popup_window_item_icon)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PopupWindowHolder {
        val popupWindowHolder = PopupWindowHolder(
            LayoutInflater.from(context).inflate(R.layout.doctor_popup_window_items, parent, false)
        )
        popupWindowHolder.itemView.setOnClickListener {
            listener(popupWindowHolder.adapterPosition)
        }
        return popupWindowHolder
    }

    override fun onBindViewHolder(holder: PopupWindowHolder, position: Int) {
        if (dataList[position].checked) {
            holder.itemIcon.isVisible = true
        } else {
            holder.itemIcon.isGone = true
        }
        holder.itemText.text = dataList[position].deskName
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}